<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>

<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <div class="form-group">

                        <label class="control-label col-sm-1">SKU:</label>
                        <div class="col-sm-2">
                            <input type="text" id="coefficientSku" name="coefficientSku" class="form-control">
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
        </div>
        <!-- END 右侧数据 -->
    </div>
</div>


<div id="toolbar" class="btn-group" style="margin-bottom:5px;">
    <button  class="layui-btn  layui-btn-sm" >
        <i class="fa fa-download"></i>
        <a href="/excel/SKU申报系数.xlsx" style="color: white" download>模板下载</a>
    </button>
    <button  class="layui-btn layui-btn-sm import-btn" style="margin-left: -2px"  id="import-btn"  name="import-btn">
        <i class="layui-icon"></i>导入SKU申报系数
    </button>
</div>
<!-- START 数据表格 -->
<table id="coefficientTable"
       data-toolbar="#toolbar"
       data-pagination="true"
       data-resizable="true"
       data-side-pagination="server"
       data-url="/sea/physical/coefficientSku/findByCnd.do"
       data-page-size="15"
       class="table table-striped table-hover"
>
</table>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui'}){}%>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/physical/coefficientSku/import/', //上传接口

            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $coefficientTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });


    var $coefficientTable = $('#coefficientTable');
    $(function () {

        // START 表格配置
        $coefficientTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '渠道',
                    field: 'coefficientChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title : 'SKU',
                    field: 'coefficientSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title : '系数',
                    field: 'coefficientCoef',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                // 删除
                $('.del-coefficient-btn').on('click',function () {
                    var id = $(this).attr('data-val');
                    layer.confirm('确定删除？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/physical/coefficientSku/delete.do',{id: id},function(data){
                            if( data.ok ){
                                $("#coefficientTable").bootstrapTable('refresh');
                                layer.msg(data.msg,{icon: 1,time: 1500});
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

                // 修改
                $('.edit-coefficient-btn').on('click',function () {
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    var coef = $(this).attr('data-val-coef');
                    $("#coefficientCoef").val(coef);
                    var code = $(this).attr('data-val-code');
                    $("#coefficientCode").val(code);
                    layer.open({
                        type:1,
                        title:'修改申报系数',
                        area:['600px','300px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_edit_window')
                    })
                });
            }
        });

        // 条件查询


        // 添加
        $('.add-btn').on('click',function () {
            layer.open({
                type:1,
                title:'新增申报系数',
                area:['600px','300px'],
                skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose:false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content:$('#layer_window')
            })
        });
    });


    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var coefficientCode=$(".coefficientCode").val();
            if(coefficientCode==''){
                parent.layer.msg('请选择国家！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var coefficientCoef=$(".coefficientCoef").val();
            if(coefficientCoef==''){
                parent.layer.msg('请填写系数！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            alert(coefficientCode);
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/physical/coefficient/save.do',{coefficientCoef:coefficientCoef,coefficientCode:coefficientCode},function(data){
                if( data.ok ){
                    $coefficientTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    //提交表单
    $('.edit-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var coefficientCode=$("#coefficientCode").val();
            if(coefficientCode==''){
                parent.layer.msg('请选择国家！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var coefficientCoef=$("#coefficientCoef").val();
            if(coefficientCoef==''){
                parent.layer.msg('请填写系数！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/physical/coefficient/usave.do',{id:$("#id").val(),coefficientCoef:coefficientCoef,coefficientCode:coefficientCode},function(data){
                if( data.ok ){
                    $coefficientTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });

    // 条件查询
    $('.search-btn').on('click',function () {
        $coefficientTable.bootstrapTable('refresh', { url:'/sea/physical/coefficientSku/findByCnd.do?'+$('#search-form').serialize() });
    });


    // 操作菜单
    function optFormatter(value,row){
        var content = '';
        content += '<button class="del-coefficient-btn btn btn-xs btn-danger" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i>  </button>';
        return content;
    }
</script>
</body>
</html>